{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 视频流去重，输出 人脸特征值map到卡夫卡"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "from kafka import KafkaProducer\n",
    "sys.path.append(r'D:\\foo')\n",
    "sys.path\n",
    "import notebook_lib.req \n",
    "import face_v2\n",
    "from matplotlib import pyplot as plt\n",
    "import numpy as np\n",
    "import json \n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "imagePath=r'C:\\Users\\user\\Pictures\\2002\\07\\19\\big'\n",
    "targetPath=r'D:\\foo\\tag\\static'\n",
    "invalidPath=r'D:\\foo\\invalid'\n",
    "req=notebook_lib.req.StSdsUtils('http://192.168.1.111:9001')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Find 2 faces to Destination \n",
      "{'C:\\\\Users\\\\user\\\\Pictures\\\\2002\\\\07\\\\19\\\\big\\\\img_356.jpg': ['D:\\\\foo\\\\tag\\\\static\\\\15337875201.jpg', 'D:\\\\foo\\\\tag\\\\static\\\\15337875202.jpg']}\n",
      "{'C:\\\\Users\\\\user\\\\Pictures\\\\2002\\\\07\\\\19\\\\big\\\\img_356.jpg': ['7qpXQoleAAAAAgAAKXIyvAFfRL1JoI+9rYBsvCeLwL2RYrQ8y9XwvLQDuzu25Ws8IPsSvI6Ad71uLoS9/1XcPQ1Qfj09JZM9BVIVvLAS2D0Xi8c8PpgFvQOwbbxWpnI8zoOCO0B5Lbt0/Yc8eWvrvDkTwTyJcxQ9jO+hOiPA67wbjzQ9Njkku+FlSTzOZl89BPIJvmwWOT2NwZE7PcSZvVX/I7125J29+6vsvCSEvjwegpS8bEIDu1k+Lb2Dvxi88qPgvEtMCj0L/3C8FSnsvGuUKzwCKPA8xKKOvM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PmCkbz5qsA9Zz0vvIcEMb0VUlS9yxu2vEMcgDzrCjg9ZZhDvba9+7xxlKS85WM/PXZqgb2uwTE6O+sWPYa2iDpgJou8kTiHuwueIr2b2eA95VV+vFlXjjzlzYw91+GtPPRjLrtYKYY88P4MvbLVhbxubUQ9hk7FO650c7uqFNq8gZMGu/Tnkr0xwaS8sgcVPTVdJ71EQJU8j+eBPYEPGzsxJjW8ghUZPeowmDsbVL08A2KoPECCajyJfZQ9BAWWvBS8Ab1lMaq8q14IPDf5TbvpIjU8A99iPFKmhD3m7uq8et10PRBY2TzqT1Y9CGoHvee9hTp2H8s7umyhu/0hGjwFDZG6S35UvCzIDbwUILU8kEUTPTg7Br1JvFY72g2cPMMt2DzQ1du8YwkCPSQkJT2T4Ei9xI/YPI+ckL0/E888nonovLtL7DxL7bk8nX4RvX27r7wq+As9wrucPTzOE70Azyk9zQddPZcpnrxIibG7Y4VDPU3W6TzS8qM7tl8fvVGKTzz5bpW7HqZmvahF/zvNWLo9FPuJPUAW8rwWuG+8VTFSPUqJ5jz/KRK9270OvULm2ry14Qo9+g4ivKwY/zsEs228UC+GvcEhujzndqo9/wUSvNb9y7xFkPK8Urd/vRfh1bsU6Rs9/VsYPBoblDxY6SE6YcYsPfpK0rwfQi49tyfLunvXCjyyZ3c9ITpXPSCpKr2f8aS89tnTO70yjL3Czsk8Ei8RPeDB8jz5oHM9trZdPLtIHLxhnom8C5AYPee14bycixC903pnO8EjOzyyLY44z9aruj1n/bua77U8f2oOvecBHbx1vPo8JKYSvQm1gz2TST+7tYR5vLoPhD0B2Zg9bCVYPfQNlr0=']}\n",
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-13-52fac0950640>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     21\u001b[0m     \u001b[0mproducer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'frameInfo'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mimageInfoB\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     22\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 23\u001b[1;33m     \u001b[0mtime\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     24\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     25\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"ok\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "imageP=r'C:\\Users\\user\\Pictures\\2002\\07\\19\\big\\img_356.jpg'\n",
    "imageInfo={}\n",
    "faceList=face_v2.detectFace(imageP,r\"D:\\foo\\tag\\static\")\n",
    "imageInfo[imageP]=faceList\n",
    "print(imageInfo)\n",
    "producer = KafkaProducer(bootstrap_servers='192.168.1.116:9092')\n",
    "resp=req.get_batch_image_features(imageInfo[imageP])\n",
    "respMap=json.loads(resp)\n",
    "#print(respMap[\"success\"])\n",
    "frameInfo={imageP:[]}\n",
    "for  i in respMap[\"success\"]:\n",
    "    frameInfo[imageP].append( i[\"feature\"])\n",
    "print(frameInfo)\n",
    "for i in range(1000):\n",
    "   \n",
    "    \n",
    "    imageInfoB=bytes(json.dumps(frameInfo),\"utf-8\")\n",
    "   # print(imageInfoB)\n",
    "    \n",
    "    \n",
    "    producer.send('frameInfo', imageInfoB)\n",
    "    print(i)\n",
    "    time.sleep(5)\n",
    "    \n",
    "print(\"ok\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "\n",
    "# func= face(func)\n",
    "@face_v2.readPicSaveFace(imagePath,targetPath,invalidPath,'.jpg','.JPG','png','PNG')\n",
    "def func():\n",
    "    print(\"=================???=======\")\n",
    "    imageList=[r\"C:\\Users\\user\\Pictures\\2002\\07\\19\\big\\img_18.jpg\",r\"C:\\Users\\user\\Pictures\\2002\\07\\19\\big\\img_90.jpg\",r\"C:\\Users\\user\\Pictures\\2002\\07\\19\\big\\img_209.jpg\"]\n",
    "    rep=json.loads(req.get_batch_image_features(imageList))\n",
    "    print(rep[\"result\"])\n",
    "#face_v2.getFaceInRtsp()\n",
    "#TODO:精准度不行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "req.get_image_feature(r'C:\\Users\\user\\Pictures\\2002\\07\\19\\big\\img_141.jpg')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "img=plt.imread(r\"D:\\foo\\frame\\image166.jpg\")\n",
    "plt.imshow(img)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
